﻿using MyCompanyName.AbpZeroTemplate.Prm.Project;
using MyCompanyName.AbpZeroTemplate.Prm.System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyCompanyName.AbpZeroTemplate.EntityFramework.Initializtion
{
    public class CreateDatabaseInitializer
        : System.Data.Entity.CreateDatabaseIfNotExists<AbpZeroTemplateDbContext>
    //: System.Data.Entity.DropCreateDatabaseIfModelChanges<AbpZeroTemplateDbContext>
    {
        protected override void Seed(AbpZeroTemplateDbContext context)
        {
            new Seed.InitialDbBuilder(context).Create();
            InitProjectRole(context);
            InitSubstance(context);
            InitProject(context);
            InitDocumentType(context);
            InitRdCenter(context);
        }









        public void InitProjectRole(AbpZeroTemplateDbContext context)
        {
            context.ProjectRoleInfo.Add(new ProjectRoleInfo()
            {
                Description = string.Empty,
                InternalRole = InternalRole.项目经理,
                IsHumanWork = true,
                IsReserved = true,
                RoleName = "PM",
                Sortfactor = 1
            });
            context.ProjectRoleInfo.Add(new ProjectRoleInfo()
            {
                Description = string.Empty,
                InternalRole = InternalRole.项目群经理,
                IsHumanWork = false,
                IsReserved = true,
                RoleName = "PMM",
                Sortfactor = 2
            });
            context.ProjectRoleInfo.Add(new ProjectRoleInfo()
            {
                Description = string.Empty,
                InternalRole = InternalRole.其它,
                IsHumanWork = false,
                IsReserved = true,
                RoleName = "SPOC",
                Sortfactor = 3
            });
            context.ProjectRoleInfo.Add(new ProjectRoleInfo()
            {
                Description = string.Empty,
                InternalRole = InternalRole.其它,
                IsHumanWork = true,
                IsReserved = true,
                RoleName = "TI",
                Sortfactor = 4
            });
            context.ProjectRoleInfo.Add(new ProjectRoleInfo()
            {
                Description = string.Empty,
                InternalRole = InternalRole.其它,
                IsHumanWork = true,
                IsReserved = true,
                RoleName = "TO",
                Sortfactor = 5
            });
            context.ProjectRoleInfo.Add(new ProjectRoleInfo()
            {
                Description = string.Empty,
                InternalRole = InternalRole.其它,
                IsHumanWork = true,
                IsReserved = true,
                RoleName = "TLI",
                Sortfactor = 6
            });
            context.ProjectRoleInfo.Add(new ProjectRoleInfo()
            {
                Description = string.Empty,
                InternalRole = InternalRole.其它,
                IsHumanWork = true,
                IsReserved = true,
                RoleName = "成员",
                Sortfactor = 7
            });
        }


        public void InitSubstance(AbpZeroTemplateDbContext context)
        {
            for (int i = 1; i < 50; i++)
            {
                context.Substance.Add(new Substance()
                {
                    CAS = "192-168-1-1" + i,
                    CDX = "",
                    ChemDrawName = "ChemDrawName" + i,
                    CnName = "CnName" + i,
                    EnName = "EnName" + i,
                    Formula = "Formula" + i,
                    HighRisk = "HighRisk" + i,
                    MOL = "",
                    MolecularWeight = i,
                    MolPngBase64 = "",
                    Note = "Note" + i
                });
            }
        }


        public void InitProject(AbpZeroTemplateDbContext context)
        {
            context.ProjectInfo.Add(new ProjectInfo()
            {
                Status = Status.准备,
                ProjectNo = "Prm101",
                ProjectName = "恩替卡韦合成",
                Address = "上海",
                Customer = "九洲",
                RdCenter = "上海",
                Lab = "研究二室",
                CustomeCode = "001",
                PlanStartDate = DateTime.Now,
                PlanEndDate = DateTime.Now.AddMonths(2),
                TargetEndDate = DateTime.Now.AddMonths(1),
                ActualStartDate = new DateTime(1990, 1, 1),
                ActualEndDate = new DateTime(1990, 1, 1),
                PrmCommentStatus = CommentStatus.草稿,
                TeamCommentStatus = CommentStatus.草稿
            });
        }

        public void InitDocumentType(AbpZeroTemplateDbContext context)
        {
            context.DocumentType.Add(new DocumentType()
            {
                Id = 0,
                RootName = "研发部",
                ParentName = "总结报告",
                OrderNo = 1,
                Name = "技术总结报告",
                Description = "技术总结报告",
                IsEnabled = true
            });
            context.DocumentType.Add(new DocumentType()
            {
                Id = 0,
                RootName = "研发部",
                ParentName = "总结报告",
                OrderNo = 2,
                Name = "分析总结报告",
                Description = "分析总结报告",
                IsEnabled = true
            });
            context.DocumentType.Add(new DocumentType()
            {
                Id = 0,
                RootName = "",
                ParentName = "",
                OrderNo = 3,
                Name = "背景报告",
                Description = "背景报告",
                IsEnabled = true
            });
            context.DocumentType.Add(new DocumentType()
            {
                Id = 0,
                RootName = "",
                ParentName = "",
                OrderNo = 4,
                Name = "安全报告",
                Description = "安全报告",
                IsEnabled = true
            });
            context.DocumentType.Add(new DocumentType()
            {
                Id = 0,
                RootName = "",
                ParentName = "",
                OrderNo = 5,
                Name = "其它",
                Description = "其它",
                IsEnabled = true
            });
        }



        public void InitRdCenter(AbpZeroTemplateDbContext context)
        {
            context.RdCenter.Add(new RdCenter()
            {
                Id = 0,
                Name = "浙江研发中心",
                Principal = "debug",
                Laboratory = new List<Laboratory>() { 
                    new Laboratory(){
                        Id = 0,
                        Name = "第一研究室",
                        Principal = "debug"
                    }
                }
            });
        }

    }
}
